/*
 * BackupListFrame.java
 *
 * Created on December 16, 2007, 5:01 PM
 */
package backupit.gui;

import backupit.GUILauncher;
import backupit.Settings;
import backupit.core.Backup;
import backupit.core.dirbackup.DirBackup;
import backupit.core.BackupList;
import backupit.core.BackupFactory;
import backupit.core.ResourceIdentifier;
import backupit.core.io.LoadBackupList;
import java.awt.Component;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JProgressBar;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

class BackupListFilter extends javax.swing.filechooser.FileFilter {

    public boolean accept(File file) {
        String filename = file.getName();
        return filename.endsWith(Settings.BACKUPLIST_EXTENSION);
    }

    public String getDescription() {
        return "*" + Settings.BACKUPLIST_EXTENSION;
    }
    }


class ProgRenderer implements TableCellRenderer {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        return (JProgressBar) value;
    }
 
}
/**
 *
 * @author  dbotelho
 */
public class BackupListFrame extends javax.swing.JFrame {

    private Settings settings;
    public static final String STATUS_COLUMN = "Status";
    //private static final int statusIdx = 1;
    private static final String nameColumn = "Name";
    //private static final int nameIdx = 2;
    private static final String sourceColumn = "Source";
    //private static final int sourceIdx = 3;
    private static final String destinationColumn = "Destination";
    //private static final int destinationIdx = 4;
    private static final String hiddenColumn = "Hidden";
    //private static final int hidden = 7;
    private static final String updateColumn = "Update";
    //private static final int update = 6;
    private static final String recursiveColumn = "Recursive";
    //private static final int recursive = 5;
    private static final String simulateColumn = "Simulate";
    //private static final int simulate = 8;
    
    private GUILauncher guiLauncher;

    /** Creates new form BackupListFrame */
    public BackupListFrame(GUILauncher guiLauncher) {
        this.guiLauncher = guiLauncher;
               
        try {
            // Set System L&F
            UIManager.setLookAndFeel(
                    UIManager.getSystemLookAndFeelClassName());
            System.out.println(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // handle exception
            e.printStackTrace();
        } catch (InstantiationException e) {
            // handle exception
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // handle exception
            e.printStackTrace();
        }
        this.settings = guiLauncher.getSettings();
        initComponents();
        
        backupTable.getColumn(STATUS_COLUMN).setCellRenderer(new ProgRenderer());
        loadLooknFeel();
        updateBackupManagerCheckBoxMenuItem();
    }

    private void setAllLooknFeelRadioButtons(boolean selected) {
        for (int i = 0; i < windowMenu1.getItemCount(); i++) {
            ((javax.swing.JRadioButtonMenuItem) windowMenu1.getItem(i)).setSelected(selected);
        }
    }
    public void updateUI(String looknFeel) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{
        //UIManager.updateUI(looknFeel);
        this.repaint();
    }

    private void looknFeelRadioButtonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            // TODO add your handling code here:
            javax.swing.JRadioButtonMenuItem looknFeel = (JRadioButtonMenuItem) evt.getSource();
            System.out.println(evt.getSource());
            guiLauncher.updateUI(looknFeel.getText());
            setAllLooknFeelRadioButtons(false);
            looknFeel.setSelected(true);

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        SwingUtilities.updateComponentTreeUI(this);
    }

    private void loadLooknFeel() {
        javax.swing.JRadioButtonMenuItem newLooknFeel;
        UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
        for (int i = 0; i < info.length; i++) {
            String humanReadableName = info[i].getClassName();

            newLooknFeel = new javax.swing.JRadioButtonMenuItem(humanReadableName);
            newLooknFeel.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    looknFeelRadioButtonMenuItemActionPerformed(evt);
                }
            });
            System.out.println("Added to windowMenu: "+newLooknFeel.getText());
            windowMenu1.add(newLooknFeel);
            
        }
    }

    public void loadBackupList(BackupList backupList) {
        DefaultTableModel model = (DefaultTableModel) getBackupTable().getModel();
        for (int i = 0; i < model.getRowCount(); i++) {
            model.removeRow(i);
        }
        for (Backup b : backupList) {
            addBackup((DirBackup)b);
        }
    }

    public BackupList readBackupList() {
        BackupList backupList = new BackupList();
        for (int i = 0; i < getBackupTable().getRowCount(); i++) {
            DirBackup backup = BackupFactory.getDirBackupInstance(
                        (String) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(nameColumn)),
                        (ResourceIdentifier) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(sourceColumn)),
                        (ResourceIdentifier) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(destinationColumn)),
                        (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(hiddenColumn)),
                        (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(updateColumn)),
                        (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(recursiveColumn)), 
                        false);
            backupList.add(backup);

        }
        return backupList;
    }

    void addBackup(DirBackup backup) {
        DefaultTableModel model = (DefaultTableModel) getBackupTable().getModel();
        model.insertRow(model.getRowCount(),
                new Object[]{
            true,
            new JProgressBar(),
            backup.getName(),
            backup.getSource(),
            backup.getDestination(),
            backup.getRecursive(),
            backup.getUpdate(),
            backup.getHidden()
        });
        backupAllButton.setEnabled(getBackupTable().getRowCount()>0);
    }

    public javax.swing.JTable getBackupTable() {
        return backupTable;
    }

    public javax.swing.JLabel getStatusLabel() {
        return statusLabel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        statusPanel = new javax.swing.JPanel();
        statusLabel = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        backupAllButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        backupTable = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu1 = new javax.swing.JMenu();
        openMenuItem1 = new javax.swing.JMenuItem();
        saveMenuItem1 = new javax.swing.JMenuItem();
        saveAsMenuItem1 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        exitMenuItem1 = new javax.swing.JMenuItem();
        editMenu1 = new javax.swing.JMenu();
        cutMenuItem1 = new javax.swing.JMenuItem();
        copyMenuItem1 = new javax.swing.JMenuItem();
        pasteMenuItem1 = new javax.swing.JMenuItem();
        deleteMenuItem1 = new javax.swing.JMenuItem();
        viewMenu1 = new javax.swing.JMenu();
        backupManagerCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        windowMenu1 = new javax.swing.JMenu();
        helpMenu1 = new javax.swing.JMenu();
        contentsMenuItem1 = new javax.swing.JMenuItem();
        aboutMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("BackupIt");

        statusPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap(393, Short.MAX_VALUE)
                .addComponent(statusLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusLabel)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setMaximumSize(new java.awt.Dimension(32767, 33));
        jToolBar1.setMinimumSize(new java.awt.Dimension(222, 33));
        jToolBar1.setPreferredSize(new java.awt.Dimension(100, 33));

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/list-add_32x32.png"))); // NOI18N
        jButton2.setBorderPainted(false);
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setMaximumSize(new java.awt.Dimension(32, 32));
        jButton2.setMinimumSize(new java.awt.Dimension(32, 32));
        jButton2.setPreferredSize(new java.awt.Dimension(32, 32));
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/list-remove_32x32.png"))); // NOI18N
        jButton3.setBorderPainted(false);
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setMaximumSize(new java.awt.Dimension(32, 32));
        jButton3.setMinimumSize(new java.awt.Dimension(32, 32));
        jButton3.setPreferredSize(new java.awt.Dimension(32, 32));
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/edit-copy_32x32.png"))); // NOI18N
        jButton4.setBorderPainted(false);
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setMaximumSize(new java.awt.Dimension(32, 32));
        jButton4.setMinimumSize(new java.awt.Dimension(32, 32));
        jButton4.setPreferredSize(new java.awt.Dimension(32, 32));
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);

        backupAllButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/xarchive_32x32.png"))); // NOI18N
        backupAllButton.setText("Backup All");
        backupAllButton.setBorderPainted(false);
        backupAllButton.setEnabled(false);
        backupAllButton.setFocusable(false);
        backupAllButton.setMaximumSize(new java.awt.Dimension(114, 32));
        backupAllButton.setMinimumSize(new java.awt.Dimension(114, 32));
        backupAllButton.setPreferredSize(new java.awt.Dimension(114, 32));
        backupAllButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        backupAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backupAllButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(backupAllButton);

        backupTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Status", "Name", "Source", "Destination", "Recursive", "Update", "Hidden"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(backupTable);

        fileMenu1.setText("File");

        openMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/document-open_16x16.png"))); // NOI18N
        openMenuItem1.setText("Open");
        openMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu1.add(openMenuItem1);

        saveMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/document-save_16x16.png"))); // NOI18N
        saveMenuItem1.setText("Save");
        saveMenuItem1.setEnabled(false);
        fileMenu1.add(saveMenuItem1);

        saveAsMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/document-save-as_16x16.png"))); // NOI18N
        saveAsMenuItem1.setText("Save As ...");
        saveAsMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });
        fileMenu1.add(saveAsMenuItem1);
        fileMenu1.add(jSeparator1);

        exitMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/backupit/gui/pixmaps/system-log-out_16x16.png"))); // NOI18N
        exitMenuItem1.setText("Exit");
        exitMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu1.add(exitMenuItem1);

        jMenuBar1.add(fileMenu1);

        editMenu1.setText("Edit");
        editMenu1.setEnabled(false);

        cutMenuItem1.setText("Cut");
        editMenu1.add(cutMenuItem1);

        copyMenuItem1.setText("Copy");
        editMenu1.add(copyMenuItem1);

        pasteMenuItem1.setText("Paste");
        editMenu1.add(pasteMenuItem1);

        deleteMenuItem1.setText("Delete");
        editMenu1.add(deleteMenuItem1);

        jMenuBar1.add(editMenu1);

        viewMenu1.setText("View");
        viewMenu1.addMenuListener(new javax.swing.event.MenuListener() {
            public void menuCanceled(javax.swing.event.MenuEvent evt) {
            }
            public void menuDeselected(javax.swing.event.MenuEvent evt) {
            }
            public void menuSelected(javax.swing.event.MenuEvent evt) {
                viewMenu1MenuSelected(evt);
            }
        });

        backupManagerCheckBoxMenuItem.setSelected(true);
        backupManagerCheckBoxMenuItem.setText("Backup Manager");
        backupManagerCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backupManagerCheckBoxMenuItemActionPerformed(evt);
            }
        });
        viewMenu1.add(backupManagerCheckBoxMenuItem);

        jMenuBar1.add(viewMenu1);

        windowMenu1.setText("Window");
        jMenuBar1.add(windowMenu1);

        helpMenu1.setText("Help");
        helpMenu1.setEnabled(false);

        contentsMenuItem1.setText("Contents");
        helpMenu1.add(contentsMenuItem1);

        aboutMenuItem1.setText("About");
        helpMenu1.add(aboutMenuItem1);

        jMenuBar1.add(helpMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(statusPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void backupAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backupAllButtonActionPerformed
this.guiLauncher.getBackupManager().getBackupManagerGUI().setVisible(true);
        for (int i = 0; i < getBackupTable().getRowCount(); i++) {
            if ((Boolean) getBackupTable().getValueAt(i, 0)) {
                try {
                    DirBackup backup = BackupFactory.getDirBackupInstance(
                            (String) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(nameColumn)),
                            (ResourceIdentifier) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(sourceColumn)),
                            (ResourceIdentifier) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(destinationColumn)),
                            (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(hiddenColumn)),
                            (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(updateColumn)),
                            (Boolean) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(recursiveColumn)),
                            false);
                    this.guiLauncher.getBackupManager().execute(i,backup);
                    //new Thread(new ExecuteBackupGUI(this, (JProgressBar) getBackupTable().getValueAt(i, getBackupTable().getColumnModel().getColumnIndex(STATUS_COLUMN)), backup)).start();

                } catch (IOException ex) {
                    Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
}//GEN-LAST:event_backupAllButtonActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        CreateBackupDialog viewBackupGUI = new CreateBackupDialog(this);
        viewBackupGUI.pack();
        viewBackupGUI.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.addChoosableFileFilter(new BackupListFilter());

        chooser.setCurrentDirectory(new File(Settings.ROOT_DIR));
        int returnVal = chooser.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
//                System.out.println("You chose to open this file: " + 
//                        chooser.getSelectedFile()+" "+
//                        chooser.getSelectedFile().getName());
                String file = (chooser.getSelectedFile().getName().endsWith(Settings.BACKUPLIST_EXTENSION)) ? chooser.getSelectedFile().getPath() : chooser.getSelectedFile().getPath() + Settings.BACKUPLIST_EXTENSION;
                //System.out.println("You chose to open this file: "+file);
                settings.saveBackupList(file, this.readBackupList());
            } catch (FileNotFoundException ex) {
                Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_saveAsMenuItemActionPerformed

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.addChoosableFileFilter(new BackupListFilter());

        chooser.setCurrentDirectory(new File(Settings.ROOT_DIR));


        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            //            System.out.println("You chose to open this file: " +
            //                    chooser.getSelectedFile().getName());
            try {
                loadBackupList(this.settings.loadBackupList(chooser.getSelectedFile().getPath()));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InterruptedException ex) {
                Logger.getLogger(BackupListFrame.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        DefaultTableModel model = (DefaultTableModel) getBackupTable().getModel();
        getBackupTable().getSelectedRow();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        DefaultTableModel model = (DefaultTableModel) getBackupTable().getModel();
        model.removeRow(getBackupTable().getSelectedRow());
    }//GEN-LAST:event_jButton3ActionPerformed

    public void updateBackupManagerCheckBoxMenuItem(){
        this.backupManagerCheckBoxMenuItem.setSelected(this.guiLauncher.getBackupManager().getBackupManagerGUI().isVisible());
    }
    private void backupManagerCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backupManagerCheckBoxMenuItemActionPerformed
        this.guiLauncher.getBackupManager().getBackupManagerGUI().setVisible( this.backupManagerCheckBoxMenuItem.isSelected());
        updateBackupManagerCheckBoxMenuItem();
}//GEN-LAST:event_backupManagerCheckBoxMenuItemActionPerformed

    private void viewMenu1MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_viewMenu1MenuSelected
        this.updateBackupManagerCheckBoxMenuItem();
    }//GEN-LAST:event_viewMenu1MenuSelected
    /**
     * @param args the command line arguments
     *
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new BackupListFrame().setVisible(true);
    }
    });        System.out.println("ADASDSAD");
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem1;
    private javax.swing.JButton backupAllButton;
    private javax.swing.JCheckBoxMenuItem backupManagerCheckBoxMenuItem;
    private javax.swing.JTable backupTable;
    private javax.swing.JMenuItem contentsMenuItem1;
    private javax.swing.JMenuItem copyMenuItem1;
    private javax.swing.JMenuItem cutMenuItem1;
    private javax.swing.JMenuItem deleteMenuItem1;
    private javax.swing.JMenu editMenu1;
    private javax.swing.JMenuItem exitMenuItem1;
    private javax.swing.JMenu fileMenu1;
    private javax.swing.JMenu helpMenu1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JMenuItem openMenuItem1;
    private javax.swing.JMenuItem pasteMenuItem1;
    private javax.swing.JMenuItem saveAsMenuItem1;
    private javax.swing.JMenuItem saveMenuItem1;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JMenu viewMenu1;
    private javax.swing.JMenu windowMenu1;
    // End of variables declaration//GEN-END:variables

    public GUILauncher getGuiLauncher() {
        return guiLauncher;
    }

    public void setGuiLauncher(GUILauncher guiLauncher) {
        this.guiLauncher = guiLauncher;
    }

}
